/*
* Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于jv-rover系统.
*/
package com.pitop.device.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.device.entity.DeviceOnline;
import com.pitop.device.service.DeviceOnlineSV;

/**
 * 在线设备 控制器
 *
 * @author lixin
 */
@RestController
@RequestMapping("/deviceOnline")
@Slf4j
@Api(value = "在线设备控制器", description = "在线设备控制器")
public class DeviceOnlineCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private DeviceOnlineSV deviceOnlineSV;

    /**
     * 查询DeviceOnline一个详情信息
     *
     * @param id
     * @param groupCode      组编码
     * @param groupName      组名称
     * @param deviceCode     设备编码
     * @param deviceCodeName 设备代码
     * @return BeanRet
     */
    @ApiOperation(value = "查询DeviceOnline一个详情信息", notes = "查询DeviceOnline一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "groupCode", value = "组编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "groupName", value = "组名称", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public DeviceOnline load(java.lang.Long id, java.lang.String groupCode, java.lang.String groupName, java.lang.String deviceCode, java.lang.String deviceCodeName) {
        if (id == null) {
            return null;
        }
        if (groupCode == null) {
            return null;
        }
        if (groupName == null) {
            return null;
        }
        if (deviceCode == null) {
            return null;
        }
        if (deviceCodeName == null) {
            return null;
        }
        DeviceOnline deviceOnline = deviceOnlineSV.load(id, groupCode, groupName, deviceCode, deviceCodeName);
        log.info(JSON.toJSONString(deviceOnline));
        return deviceOnline;
    }


    /**
     * 根据条件id查询DeviceOnline一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询DeviceOnline一个详情信息", notes = "查询DeviceOnline一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public DeviceOnline loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        DeviceOnline deviceOnline = deviceOnlineSV.loadById(id);
        log.info(JSON.toJSONString(deviceOnline));
        return deviceOnline;
    }

    /**
     * 根据条件groupCode查询DeviceOnline一个详情信息
     *
     * @param groupCode 组编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询DeviceOnline一个详情信息", notes = "查询DeviceOnline一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupCode", value = "组编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/groupCode/{groupCode}")
    @ResponseBody
    public DeviceOnline loadByGroupCode(@PathVariable java.lang.String groupCode) {
        if (groupCode == null) {
            return null;
        }
        DeviceOnline deviceOnline = deviceOnlineSV.loadByGroupCode(groupCode);
        log.info(JSON.toJSONString(deviceOnline));
        return deviceOnline;
    }

    /**
     * 根据条件groupName查询DeviceOnline一个详情信息
     *
     * @param groupName 组名称
     * @return BeanRet
     */
    @ApiOperation(value = "查询DeviceOnline一个详情信息", notes = "查询DeviceOnline一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupName", value = "组名称", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/groupName/{groupName}")
    @ResponseBody
    public DeviceOnline loadByGroupName(@PathVariable java.lang.String groupName) {
        if (groupName == null) {
            return null;
        }
        DeviceOnline deviceOnline = deviceOnlineSV.loadByGroupName(groupName);
        log.info(JSON.toJSONString(deviceOnline));
        return deviceOnline;
    }

    /**
     * 根据条件deviceCode查询DeviceOnline一个详情信息
     *
     * @param deviceCode 设备编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询DeviceOnline一个详情信息", notes = "查询DeviceOnline一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/deviceCode/{deviceCode}")
    @ResponseBody
    public DeviceOnline loadByDeviceCode(@PathVariable java.lang.String deviceCode) {
        if (deviceCode == null) {
            return null;
        }
        DeviceOnline deviceOnline = deviceOnlineSV.loadByDeviceCode(deviceCode);
        log.info(JSON.toJSONString(deviceOnline));
        return deviceOnline;
    }

    /**
     * 根据条件deviceCodeName查询DeviceOnline一个详情信息
     *
     * @param deviceCodeName 设备代码
     * @return BeanRet
     */
    @ApiOperation(value = "查询DeviceOnline一个详情信息", notes = "查询DeviceOnline一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/deviceCodeName/{deviceCodeName}")
    @ResponseBody
    public DeviceOnline loadByDeviceCodeName(@PathVariable java.lang.String deviceCodeName) {
        if (deviceCodeName == null) {
            return null;
        }
        DeviceOnline deviceOnline = deviceOnlineSV.loadByDeviceCodeName(deviceCodeName);
        log.info(JSON.toJSONString(deviceOnline));
        return deviceOnline;
    }


    /**
     * 查询DeviceOnline信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询DeviceOnline信息集合", notes = "查询DeviceOnline信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<DeviceOnline> list(@RequestBody @ApiIgnore DeviceOnline deviceOnline, Integer curPage, Integer pageSize) {
        Page<DeviceOnline> page = new Page<DeviceOnline>(pageSize, curPage);
        List<DeviceOnline> deviceOnlines = deviceOnlineSV.list(deviceOnline, page.genRowStart(), page.getPageSize());
        int total = deviceOnlineSV.count(deviceOnline);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return deviceOnlines;
    }


    /**
     * 查询DeviceOnline信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询DeviceOnline信息集合", notes = "查询DeviceOnline信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "groupCode", value = "组编码", paramType = "query"),
            @ApiImplicitParam(name = "groupName", value = "组名称", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<DeviceOnline> listByPk(java.lang.Long id, java.lang.String groupCode, java.lang.String groupName, java.lang.String deviceCode, java.lang.String deviceCodeName, Integer curPage, Integer pageSize) {
        Page<DeviceOnline> page = new Page<DeviceOnline>(pageSize, curPage);
        List<DeviceOnline> deviceOnlines = deviceOnlineSV.list(id, groupCode, groupName, deviceCode, deviceCodeName, page.genRowStart(), page.getPageSize());
        int total = deviceOnlineSV.count(id, groupCode, groupName, deviceCode, deviceCodeName);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return deviceOnlines;
    }

    /**
     * 统计DeviceOnline信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计DeviceOnline信息数量根据主键", notes = " 统计DeviceOnline信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "groupCode", value = "组编码", paramType = "query"),
            @ApiImplicitParam(name = "groupName", value = "组名称", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String groupCode, java.lang.String groupName, java.lang.String deviceCode, java.lang.String deviceCodeName) {
        return deviceOnlineSV.count(id, groupCode, groupName, deviceCode, deviceCodeName);
    }

    /**
     * 统计DeviceOnline信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计DeviceOnline信息数量", notes = "统计DeviceOnline信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "groupCode", value = "组编码", paramType = "query"),
            @ApiImplicitParam(name = "groupName", value = "组名称", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", paramType = "query"),
            @ApiImplicitParam(name = "token", value = "当前token", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "账户编码来自futerther", paramType = "query"),
            @ApiImplicitParam(name = "username", value = "用户名", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "用户邮箱", paramType = "query"),
            @ApiImplicitParam(name = "os", value = "os版本信息", paramType = "query"),
            @ApiImplicitParam(name = "ip", value = "当前ip", paramType = "query"),
            @ApiImplicitParam(name = "port", value = "端口", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody DeviceOnline deviceOnline) {
        if (deviceOnline == null) {
            return deviceOnlineSV.count(new HashMap());
        } else {
            return deviceOnlineSV.count(deviceOnline);
        }
    }


    /**
     * 创建DeviceOnline
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建DeviceOnline", notes = "创建DeviceOnline")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "当前token", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "账户编码来自futerther", paramType = "query"),
            @ApiImplicitParam(name = "username", value = "用户名", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "用户邮箱", paramType = "query"),
            @ApiImplicitParam(name = "os", value = "os版本信息", paramType = "query"),
            @ApiImplicitParam(name = "ip", value = "当前ip", paramType = "query"),
            @ApiImplicitParam(name = "port", value = "端口", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public DeviceOnline build(@RequestBody @ApiIgnore DeviceOnline deviceOnline) {
        deviceOnlineSV.save(deviceOnline);
        return deviceOnline;
    }


    /**
     * 修改DeviceOnline
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改DeviceOnline", notes = "修改DeviceOnline")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "groupCode", value = "组编码", paramType = "query"),
            @ApiImplicitParam(name = "groupName", value = "组名称", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", paramType = "query"),
            @ApiImplicitParam(name = "token", value = "当前token", paramType = "query"),
            @ApiImplicitParam(name = "accountCode", value = "账户编码来自futerther", paramType = "query"),
            @ApiImplicitParam(name = "username", value = "用户名", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "用户邮箱", paramType = "query"),
            @ApiImplicitParam(name = "os", value = "os版本信息", paramType = "query"),
            @ApiImplicitParam(name = "ip", value = "当前ip", paramType = "query"),
            @ApiImplicitParam(name = "port", value = "端口", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public DeviceOnline modify(@ApiIgnore DeviceOnline deviceOnline) {
        deviceOnlineSV.modify(deviceOnline);
        return deviceOnline;
    }

    /**
     * 删除DeviceOnline
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除DeviceOnline", notes = "删除DeviceOnline")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "groupCode", value = "组编码", paramType = "query"),
            @ApiImplicitParam(name = "groupName", value = "组名称", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCodeName", value = "设备代码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String groupCode, java.lang.String groupName, java.lang.String deviceCode, java.lang.String deviceCodeName) {
        deviceOnlineSV.delete(id, groupCode, groupName, deviceCode, deviceCodeName);
        return BeanRet.create(true, "删除DeviceOnline成功");
    }

}
